Public Class SADSendMail
    Private msSMTP As String
    Private msUID As String
    Private msPWD As String

    Public Sub New()
        Dim oConfiguration As New SQLAutoDocLib.Config_Factory

        msSMTP = oConfiguration.GetValueFromName("MAIL_SMTP")
        msUID = oConfiguration.GetValueFromName("MAIL_USR")
        msPWD = oConfiguration.GetValueFromName("MAIL_PWD")
    End Sub

    Public Sub New( _
        ByVal sSMTP As String, _
        ByVal sUID As String, _
        ByVal sPWD As String)

        msSMTP = sSMTP
        msUID = sUID
        msPWD = sPWD
    End Sub

    Public Function SendMessage( _
        ByVal sSubject As String, _
        ByVal sMessage As String, _
        Optional ByVal sSender As String = "", _
        Optional ByVal sRecipients As String = "", _
        Optional ByVal sAttachmentPath As String = "") As String

        Dim oConfiguration As New SQLAutoDocLib.Config_Factory

        Dim sFrom As String = oConfiguration.GetValueFromName("MAIL_SENDER")
        Dim sTo As String = oConfiguration.GetValueFromName("MAIL_RECIPIENT")

        If sSender > "" Then
            sFrom = sSender
        End If

        If sRecipients > "" Then
            sTo = sRecipients
        End If

        Dim oMessage As New JMail.Message
        oMessage.Subject = sSubject
        oMessage.Message = sMessage
        oMessage.RecipientAddressList = sTo
        oMessage.SenderEmail = sFrom
        oMessage.SenderName = sFrom

        If sAttachmentPath > "" Then
            oMessage.AttachmentList = sAttachmentPath
        End If

        Dim oSender As New JMail.SendEmail
        Return oSender.SendThisMessage(oMessage, msSMTP, msUID, msPWD)
    End Function
End Class
